﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Com.CMS263.PO;
using Com.CMS263.BLL;
using Com.CMS263.Util;
namespace Com.CMS263.Web.manage
{
    public partial class AddArtType : System.Web.UI.Page
    {
        int pid;
        ArtTypeBLL atb = new ArtTypeBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
             pid = string.IsNullOrEmpty(Request["pid"]) ? 0 : int.Parse(Request["pid"]);
            this.hdfpid.Value = pid.ToString();
            if (!this.IsPostBack)
            {
                this.BindType();
                this.BindList();
            }

        }
        void BindList()
        {
            IList<AttributeType> typeList = (new AttributeTypeBLL()).GetAllAttributeType();
            this.ddlList.DataSource = typeList;
            this.ddlList.DataBind();

        }
        public void BindType()
        {

            IList<Com.CMS263.PO.ArtType> list = atb.GetArtTypeByPid(pid);
            this.rptList.DataSource = list;
            this.rptList.DataBind();
        }
        public void del(Object sender, CommandEventArgs args)
        { 
            
        }

        protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int id =int.Parse( e.CommandArgument.ToString());
            string cmdName = e.CommandName;
            atb.DeleteTypeById(id);
            
            this.BindType();
            string menu = atb.GetTypeTree();
            FileUtil.WriteToFile(Server.MapPath("/manage/menutext/menu.txt"), menu);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string typeName = StringUtil.checkStr( this.typeName.Text);
            int orderId = string.IsNullOrEmpty(this.txtOrderId.Text) ? 0 : int.Parse(this.txtOrderId.Text);
            string outApp = StringUtil.checkStr(Request["oupApp"]);
            
            Com.CMS263.PO.ArtType at = new Com.CMS263.PO.ArtType();
            at.outLink = int.Parse(Request["outApp"]);
            at.typeName = typeName;
            at.orderId = orderId;
            if (chkShow.Checked)
            {
                at.isShow = 1;
            }
            else {
                at.isShow = 0;
            }
            at.pid = int.Parse(this.hdfpid.Value);
            atb.Add(at);
          //更新后台菜单
            string menu = atb.GetTypeTree();
            FileUtil.WriteToFile(Server.MapPath("/manage/menutext/menu.txt"), menu);

            StringUtil.Alert("添加成功","addArtType.aspx?pid="+pid.ToString());
        }
        public string GetOutLinkName(object id)
        {
            AttributeTypeBLL atbll = new AttributeTypeBLL();
            int ids = Convert.ToInt32(id);
            if (ids > 0)
            {
                return atbll.GetAttributeById(ids).typeName;
            }
            else
            {
                return "父类链接";
            }
        }
    }
}
